package com.zbkj.admin.controller.platform;

import com.zbkj.common.model.UserModelUrl;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.PageParamRequest;
import com.zbkj.common.result.CommonResult;
import com.zbkj.service.service.SystemAttachmentService;
import com.zbkj.service.service.UserModelUrlService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


/**
 * 用户模特地址表 前端控制器
 */
@Slf4j
@RestController
@RequestMapping("api/admin/platform/user/model/url")
@Api(tags = "用户模特地址表")
public class UserModelUrlController {

    @Autowired
    private UserModelUrlService userModelUrlService;
    @Autowired
    private SystemAttachmentService systemAttachmentService;


    @PreAuthorize("hasAuthority('platform:user:model:list')")
    @ApiOperation(value = "用户模特地址列表")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public CommonResult<CommonPage<UserModelUrl>> getList(@RequestBody PageParamRequest pageParamRequest) {
        return CommonResult.success(CommonPage.restPage(userModelUrlService.getList(pageParamRequest)));
    }


    @PreAuthorize("hasAuthority('platform:user:model:save')")
    @ApiOperation(value = "新增用户模特地址")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public CommonResult<Object> save(@RequestBody @Validated UserModelUrl userModelUrl) {
        Boolean b = userModelUrlService.addUserModelUrl(userModelUrl);
        if (b) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }


    @PreAuthorize("hasAuthority('platform:user:model:update')")
    @ApiOperation(value = "修改用户模特地址")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public CommonResult<Object> update(@RequestBody UserModelUrl userModelUrl) {
        if (null == userModelUrl.getId()) {
            return CommonResult.failed("id不能为空");
        }
        if (userModelUrlService.updateUserModelUrlById(userModelUrl)) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }


}



